import AntModal from "@/components/pt/dialog/AntModal";
import IndexAddFiles from "../../bizassesstodeptdetails/indexAddFiles.vue";
import IndexPingFen from "../../bizassesstodeptdetails/indexPingFen.vue";
import {
  getBizAssessToDept,
  addBizAssessToDept,
  updateBizAssessToDept,
  findMaxSort,
} from "@/api/biz/bizAssessToDept";

export default {
  name: "CreateForm",
  props: {},
  components: {
    AntModal,
    IndexPingFen,
    IndexAddFiles,
  },
  data() {
    return {
      open: false,
      spinning: false,
      delayTime: 100,
      labelCol: { span: 4 },
      wrapperCol: { span: 14 },
      loading: false,
      total: 0,
      id: undefined,
      formTitle: "添加考核部门",
      // 表单参数
      form: {},
      rules: {},
      isShenhe: false,
    };
  },
  filters: {},
  created() {},
  computed: {},
  watch: {},
  mounted() {},
  methods: {
    onClose() {
      this.open = false;
      this.reset();
      this.$emit("close");
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
      this.$emit("close");
    },
    saveCaogao() {
      this.$message.success("保存草稿成功", 3);
      setTimeout(() => {
        this.open = false;
        this.$emit("close");
      }, 2000);
    },
    handleSaveDetailsFils() {
      const that = this;

      this.$confirm({
        title: "确认提交考核资料？",
        content: "提交后将进行审核！",
        onOk() {
          const saveForm = JSON.parse(JSON.stringify(that.form));
          saveForm.status = 9;
          return updateBizAssessToDept(saveForm).then(() => {
            that.open = false;
            that.$emit("ok");
            that.$message.success("提交成功", 3);
          });
        },
        onCancel() {},
      });
    },
    handleSaveDetailsKaoHe() {
      const that = this;
      this.$confirm({
        title: "确认审核考核通过？",
        content: "提交后将进行考核评分！",
        onOk() {
          that.form.status = 2;
          const saveForm = JSON.parse(JSON.stringify(that.form));
          return updateBizAssessToDept(saveForm).then(() => {
            that.open = false;
            that.$emit("ok");

            that.$message.success("提交成功", 3);
          });
        },
        onCancel() {},
      });
    },
    handleSaveDetailsPingFen() {
      const that = this;

      this.$confirm({
        title: "确认提交考核评分？",
        content: "提交后将完成考核，无法修改评分！",
        onOk() {
          that.form.status = 3;
          const saveForm = JSON.parse(JSON.stringify(that.form));
          return updateBizAssessToDept(saveForm).then(() => {
            that.open = false;
            that.$emit("ok");

            that.$message.success("提交成功", 3);
          });
        },
        onCancel() {},
      });
    },
    handleSaveback() {
      const that = this;
      this.$confirm({
        title: "确认退回考核？",
        content: "退回后可重新提交考核",
        onOk() {
          that.form.status = 1;
          const saveForm = JSON.parse(JSON.stringify(that.form));
          return updateBizAssessToDept(saveForm).then(() => {
            that.open = false;
            that.$emit("ok");
            that.$message.success("退回成功", 3);
          });
        },
        onCancel() {},
      });
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        userId: undefined,

        deptId: undefined,

        userName: undefined,

        deptName: undefined,

        companyId: undefined,

        assessId: undefined,

        assessDept: undefined,

        assessTitle: undefined,

        endTime: undefined,

        sort: undefined,

        status: undefined,
      };
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      /** 获取最大编号 */
      findMaxSort().then((response) => {
        this.form.sort = response.data;
        this.formTitle = "添加考核部门";
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.open = true;
      this.spinning = !this.spinning;
      const bizAssessToDeptId = row.id;
      getBizAssessToDept(bizAssessToDeptId).then((response) => {
        this.form = response.data;
        this.formTitle = "修改考核部门";
        this.spinning = !this.spinning;
      });
    },
    handleAddFilsUpdate(row, isShenhe) {
      this.open = true;
      this.spinning = !this.spinning;
      const bizAssessToDeptId = row.id;
      this.isShenhe = isShenhe;
      getBizAssessToDept(bizAssessToDeptId).then((response) => {
        this.form = response.data;
        this.formTitle = "提交考核资料";
        this.spinning = !this.spinning;
      });
    },
    handlePingFenUpdate(row) {
      this.reset();
      this.open = true;
      this.spinning = !this.spinning;
      const bizAssessToDeptId = row.id;
      getBizAssessToDept(bizAssessToDeptId).then((response) => {
        this.form = response.data;
        this.formTitle = "考核信息评分";
        this.spinning = !this.spinning;
      });
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs.form.validate((valid) => {
        if (valid) {
          const saveForm = JSON.parse(JSON.stringify(this.form));
          if (this.form.id !== undefined) {
            updateBizAssessToDept(saveForm).then((response) => {
              this.$message.success("修改成功", 3);
              this.open = false;
              this.$emit("ok");
              this.$emit("close");
            });
          } else {
            addBizAssessToDept(saveForm).then((response) => {
              this.$message.success("新增成功", 3);
              this.open = false;
              this.$emit("ok");
              this.$emit("close");
            });
          }
        } else {
          return false;
        }
      });
    },
    back() {
      const index = "/biz/bizassesstodept/index";
      this.$router.push(index);
    },
  },
};
